﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Event
{
    class Car
    {
        public event EventHandler<TunkIsFullEventArgs> TunkIsFull;
        public event EventHandler Running;
        private int _tunkFilledVolume;
        private const int _maxVolume = 150;
        public void AddFuel(int volue)
        {
            int diff = (_tunkFilledVolume + volue) - _maxVolume;
            if (diff > 0)
            {
                OnTunkIsFull(diff);
            }
            else
            {
                _tunkFilledVolume += volue;
            }
        }

        private void OnTunkIsFull(int diffVolue)
        {
            if (TunkIsFull != null)
            {
                var args = new TunkIsFullEventArgs() { OverCharge = diffVolue };
                TunkIsFull(this, args);
            }
        }
        
        public int TunkFilledVolume
        {
            get { return _tunkFilledVolume; }
        }

        public int TunkMaxVolume
        {
            get
            {
                return _maxVolume;
            }
        }
        public void Run()
        {
            OnRunning();
        }

        public void OnRunning()
        {
            if (Running != null)
            {
                Running(this, EventArgs.Empty);
            }
        }


    }
    public class TunkIsFullEventArgs : EventArgs
    {
        public int OverCharge { get; set; }

    }
}
